﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BookSystem;

namespace BookSystem
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        public static string id;
        public static string role;

        private void Main_Load(object sender, EventArgs e)
        {
            //设置为MDI父窗体
            this.IsMdiContainer = true;


            //获取身份验证 ==>从登录窗口获得role的label.text信息
            //获取ID ==>从登录窗口获得uid标签的信息
            Login l = (Login)this.Owner;
            role = l.Controls["role"].Text;
            id = l.Controls["uid"].Text;

            //用户权限
            userLoad();

            //管理员权限
            adminLoad();

        }


        //当角色是user的时候，加载user的权限给user
        private void userLoad() { 
        
            if(role == "1"){
                this.Text = "欢迎回来,用户：" + id;
                //一级菜单栏
                ToolStripMenuItem bookManageItem = new ToolStripMenuItem("图书操作(&B)");
                ToolStripMenuItem userManageItem = new ToolStripMenuItem("用户管理(&U)");

                menuStrip1.Items.AddRange(new ToolStripMenuItem[] { bookManageItem, userManageItem });

                //图书操作的二级菜单栏
                ToolStripMenuItem book_borrow = new ToolStripMenuItem("图书借阅");
                ToolStripMenuItem book_return = new ToolStripMenuItem("图书归还");

                bookManageItem.DropDownItems.AddRange(new ToolStripMenuItem[] { book_borrow, book_return });

                //用户管理的二级菜单栏
                ToolStripMenuItem user_update = new ToolStripMenuItem("修改密码");

                userManageItem.DropDownItems.Add(user_update);

                //用户的操作事件
                book_borrow.Click += bookManageItem_Click;
                book_return.Click += bookReturnItem_Click;
                user_update.Click += user_update_Click;
            }
        
        }

        //当角色是admin的时候，加载admin的权限给admin
        private void adminLoad()
        {

            if (role == "0")
            {
                this.Text = "欢迎回来,管理员：" + id;
                //一级菜单栏
                ToolStripMenuItem borrowManageItem = new ToolStripMenuItem("借阅情况(&O)");
                ToolStripMenuItem bookManageItem = new ToolStripMenuItem("图书管理(&B)");
                ToolStripMenuItem userManageItem = new ToolStripMenuItem("用户管理(&U)");
                ToolStripMenuItem adminManageItem = new ToolStripMenuItem("管理员管理(&A)");
                menuStrip1.Items.AddRange(new ToolStripMenuItem[] { borrowManageItem, bookManageItem, userManageItem, adminManageItem });

                borrowManageItem.Click += borrowManageItem_Click;
                bookManageItem.Click += adminGetBook_Click;
                userManageItem.Click += adminGetUser_Click;
                adminManageItem.Click += operation_Click;
            }



        }

        //《=======用户事件=========》
        //图书借阅单击事件
        private void bookManageItem_Click(object sender, EventArgs e)
        {

            User.UserGetBook usergetbook = new User.UserGetBook();
            usergetbook.MdiParent = this;
            usergetbook.Show();
        
        }

        //图书归还单击事件
        private void bookReturnItem_Click(object sender, EventArgs e)
        {
            User.ReturnBook returnbook = new User.ReturnBook();
            returnbook.MdiParent = this;
            returnbook.Show();

        }

        //修改密码单击事件操作
        private void user_update_Click(object sender, EventArgs e)
        {
            User.UserUpdatePwd userupdatepwd = new User.UserUpdatePwd();
            userupdatepwd.MdiParent = this;
            userupdatepwd.Show();

        }

        //《=======管理员事件=========》
        
        //借阅情况单击事件操作
        private void borrowManageItem_Click(object sender, EventArgs e)
        {
            Admin.Borrow borrow = new Admin.Borrow();
            borrow.MdiParent = this;
            borrow.Show();
        
        }

        //图书管理单击事件操作
        private void adminGetBook_Click(object sender, EventArgs e)
        {
            Admin.AdminGetBook admingetbook = new Admin.AdminGetBook();
            admingetbook.MdiParent = this;
            admingetbook.Show();

        }

        //用户管理单击事件操作
        private void adminGetUser_Click(object sender, EventArgs e)
        {
            Admin.AdminGetUser admingetuser = new Admin.AdminGetUser();
            admingetuser.MdiParent = this;
            admingetuser.Show();

        }

        //管理员操作单击事件操作
        private void operation_Click(object sender, EventArgs e)
        {
            Admin.Operation operation = new Admin.Operation();
            operation.MdiParent = this;
            operation.Show();

        }

        //程序退出操作
        private void Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }


    }
}
